package com.fenghongzhang.day012eventbus;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.google.android.material.tabs.TabItem;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class Main3Activity extends AppCompatActivity {
    private TabLayout tab;
    private ViewPager vp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);

        tab = (TabLayout) findViewById(R.id.tab);
        vp = (ViewPager) findViewById(R.id.vp);

        List<String> titles = new ArrayList<>();
        titles.add("首页");
        titles.add("首页二");
        titles.add("首页二");
        titles.add("首页二");
        titles.add("首页二");
        titles.add("首页二");

        tab.addTab(tab.newTab().setText("首页").setIcon(R.mipmap.ic_launcher));
        tab.addTab(tab.newTab().setText("首页二").setIcon(R.mipmap.ic_launcher));
        tab.addTab(tab.newTab().setText("首页二").setIcon(R.mipmap.ic_launcher));
        tab.addTab(tab.newTab().setText("首页二").setIcon(R.mipmap.ic_launcher));
        tab.addTab(tab.newTab().setText("首页二").setIcon(R.mipmap.ic_launcher));
        tab.addTab(tab.newTab().setText("首页二").setIcon(R.mipmap.ic_launcher));


        List<Fragment> list = new ArrayList<>();
        list.add(new BlankFragment2());
        list.add(new BlankFragment2());
        list.add(new BlankFragment2());
        list.add(new BlankFragment2());
        list.add(new BlankFragment2());
        list.add(new BlankFragment2());

        MyAdapter myAdapter = new MyAdapter(getSupportFragmentManager(), list,titles);
        vp.setAdapter(myAdapter);
        tab.setupWithViewPager(vp);

    }
}
